#ifndef MONGOOSEMGR_H_
#define MONGOOSEMGR_H_
#include "mongoose.h"
#include <functional>
#include <stdint.h>
#include <stdio.h>
#include <list>
#include <iostream>
#include <thread>
#include <mutex>
#include <chrono>
#include <map>

#include <stdint.h>
#include <string>
#include <vector>
//#include "rtpState.h"
//
//class StateData
//{
//public:
//	StateData() {}
//	~StateData() {}
//
//	std::vector<RtpState> m_RtpStateVideoReceive;
//	std::vector<RtpState> m_RtpStateVideoSender;
//
//	uint16_t remoteRtpPort = 0;
//};

class MongooseMngr
{
protected:
	MongooseMngr();

public:
	static MongooseMngr* GetInstance();

	int32_t Init(std::string exposeDir = "./",std::string ip="0.0.0.0", uint16_t port=8080,std::string name_thread = "HttpServerMeida");
	std::string GetLocalAddr();
	virtual ~MongooseMngr();

public:
	//int32_t CreateDate(uint16_t localRtpPort, StateData &oStateData);
	//void    DestoryDate(uint16_t localRtpPort);
	//void    UpdateRtpStateVideo(uint16_t localRtpPort, std::vector< RtpState> &oRtpStateVideoReceive, std::vector< RtpState>& oRtpStateVideoSender);


private:
	//std::map<uint16_t, StateData> m_StateMap;

private:
	static MongooseMngr*m_oInstance;
	static std::once_flag m_flag;
	std::mutex mutex_;


	static void OnEvent(struct mg_connection* conn, int ev, void* ev_data);

	void HandleHttpEvent(struct mg_connection* c, void* ev_data, void* user_data);
	//void VideoInfo(struct mg_connection* c);

	struct mg_mgr mgr_;
	struct mg_connection* connection_ = nullptr;
	std::unique_ptr<std::thread> poll_thread_;

	std::vector<char> m_oCacheVec;
	uint16_t m_port = 0;

	std::string m_exposeDir = "./";


	
};
std::string get_local_ip();
#endif